let rules = {
  username: { pattern: /^\w{6,12}$/, errorTip: '用户必须是 6-12 位, 只能包含数字, 字母和下划线 ' },
  password: { pattern: /(?!^[0-9]{6,12}$)(?!^[a-z]{6,12}$)(?!^[A-Z]{6,12}$)^[0-9A-Za-z]{6,12}$/, errorTip: '密码长度 6-12 位，由数字和字母组成，但必须至少包括 2 种字符' }
}

function validate(values, showError) {
  return Object.keys(rules).every((key) => {
    let rule = rules[key];
    let value = values[key];
    if (rule.pattern.test(value)) {
      return true;
    }
    else {
      showError(rule.errorTip);
      return false;
    }
  });
}

export function doLogin(values) {
  let showError = (errorTip) => {
    this.errorTip = errorTip;
    console.error(errorTip);
  }
  let ok = validate(values, showError);
  if (ok) {
    this.errorTip = '';
    console.log('ok, can submit');
    // 
  }
  return ok;
}
